package com.boang.method;

import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.Supplier;

/*
  @author: 13813
  @date: 2024/12/2 13:59
*/
public class MethodDemo {
    public static void main(String[] args) {
//        m1();
//        m2();

        Supplier<Student> supplier = () -> new Student();

        supplier = Student::new;

        Student student = supplier.get();

    }

    private static void m2() {
        Comparator<Integer> comparator = new Comparator<>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        };
        int i = comparator.compare(2, 1);
        System.out.println(i);

        comparator = (o1, o2) -> o1 - o2;
        i = comparator.compare(1, 2);
        System.out.println(i);

        /*
            如果有可直接调用的做减法运算的方法，那么就可以采用方法引用的写法
         */
        comparator = Integer::compare;
    }

    private static void m1() {
        //Consumer 匿名内部类
        /*Consumer<String> consumer = new Consumer<>() {
            @Override
            public void accept(String s) {
                System.out.println(s);

            }
        };*/
//        consumer.accept("下午茶");
        //Lambda表达式
        Consumer<String> consumer = ssss -> System.out.println(ssss);
        consumer.accept("睡一觉");
        //方法引用
        consumer = System.out::println;
        consumer.accept("写代码");
    }
}
